const mysql = require('mysql');
const dbcfg = require("./dbutils/dbcfg");
console.log(111111,dbcfg);

const con = mysql.createConnection(dbcfg.cfg);

con.connect(async e=>{
    //e undefind
    if(e){
        console.log("链接失败！错误为："+e);
    }else{
        console.log("链接成功！");
        //查询功能
        let result = await onQuery();
        console.log(result);
    }
})
//promise
function onQuery(){
    return new Promise((resolve,reject)=>{
        let sqlStr = "select * from tb_news";
        con.query(sqlStr,(e,r)=>{
            if(e){
                //err
                reject("系统错误！")
            }else{
                resolve(r);
            }
        })
    })
   
}